<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.gouwudai.gobbs.pojo.TbbsClass" %>
<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>
<%@ include file="../common/common.jsp" %>	
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限管理模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断用户类型 START
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
//判断用户类型 END
if(operatorType<2)
{
	HtmlConst.errors(out,1,"您不是该版的版主，没有当前操作的权限！");
	return;
}

userLogin.hasClassPermission(classId,4007);	//主题管理
/***************** 权限管理模块 END *********************/
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
/*************************************************************/

int listType = ParamUtils.getIntParameter(request,"listType");
String title = ParamUtils.getStringParameter(request,"title");
int topicType = ParamUtils.getIntParameter(request,"topicType");

ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
topicService.listManagePage(request);
%>

<html>
<head>
<title><%=SYSTITLE%> - <%=totalClassName.toString() %> - 主题管理</title>
<%@ include file="../common/meta.inc" %>
<link href="css/defaultStyle.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/extremetable/extremecomponents.css"/>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
<script language="javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);


function deleteInfo(id)
{
	if(!sl_confirm('删除选定的记录')) return false;

	var obj = parseInt(id);
	buffalo.remoteCall("masterGradeServiceAjaxService.delete",[obj], function(reply) {
        ajaxSubmit(reply.getResult(),"删除成功！","reload");
    });
	
}

function doConfirm(objs)
{
	var actionFlag = $F("actionFlag");
	var ids = getCheckBoxValues(objs);
	if(!sl_checkBox(objs,"主题")) return false;	
	
	if(actionFlag==1)
	{		
		if(!sl_confirm("审核主题")) return false;		
		
		buffalo.remoteCall("topicServiceAjaxService.doCheckTopic",[ids], function(reply) {
	        ajaxSubmit(reply.getResult(),"审核成功！","reload");
	    });
	}
	else if(actionFlag==2)
	{		
		if(!sl_confirm("删除主题至回收站")) return false;		
		
		buffalo.remoteCall("topicServiceAjaxService.deleteLogic",[ids], function(reply) {
	        ajaxSubmit(reply.getResult(),"删除成功！","reload");
	    });
	}
	else if(actionFlag==3)
	{		
		if(!sl_confirm("恢复主题")) return false;		
		
		buffalo.remoteCall("topicServiceAjaxService.doResume",[ids], function(reply) {
	        ajaxSubmit(reply.getResult(),"恢复成功！","reload");
	    });
	}	
}


function query()
{
	location = "class_manage_topic.jsp?listType="+document.theform.listType.value
				+"&title="+document.theform.title.value
				+"&topicType="+document.theform.topicType.value
				+"&classId="+document.theform.classId.value;
}
</script>
</head>
<body leftMargin="5" topMargin="10" rightmargin="0" bottommargin="0" >
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - <%=totalClassName.toString() %> - 主题管理');
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
	<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;主题管理
</DIV>
<DIV class="line"></DIV>
<jsp:include flush="true" page="includes/class_manage_menu.jsp?classId=<%=classId %>"></jsp:include>
<form name="theform" method="post" action="class_manage_topic.jsp">
<input type="hidden" name="classId" value="<%=classId %>">
<table width="99%" class="queryTable" align="center">
  <tr>
    <td align="right">标题:</td>
    <td align="left"><input type="text" name="title" id="title" value="<%=title %>"></td>
    <td align="right">主题状态:</td>
    <td align="left"><select name="listType" id="listType"><%=Arguments.getListTypeOptions(listType) %></select></td>
  	<td align="right">主题类型:</td>
    <td align="left"><select name="topicType" id="topicType">
    					<option value="">请选择</option>
    					<%=Arguments.getDictParamOptionsNo("T001",topicType) %>
    				</select></td>  	
  	<td align="right"><button class="btn" accessKey=q id="btnQuery" name="btnQuery" title="查询" onclick="javascript:query();">查询(<u>Q</u>)</button></td>
  </tr>  
</table>
	<ec:table 
	    form="theform"
	    view="compact"
		items="resultList"
		var="rs"	
		retrieveRowsCallback="limit"
        sortRowsCallback="limit"			
		action="${pageContext.request.contextPath}/club/class_manage_topic.jsp"		
		title="社区文章管理"
		>	
		<ec:row>
				<ec:column property="TOPIC_ID" title="标题" >
					<input type="checkbox" name="topicId" value="${rs.TOPIC_ID}">${rs.TITLE}
				</ec:column>
				<ec:column property="CLASS_NAME" title="所在版面" />
				<ec:column property="LOGIN_ID" title="作者" />
				<ec:column property="TOPIC_TYPE_NAME" title="类型"/>		
				<ec:column property="TOPIC_PRO_NAME" title="状态"/>
				<ec:switchColumn property="TOPIC_IS_PASS" title="审核" width="8%" defaultValues="false,true">
					未审核||已审核				
				</ec:switchColumn>		
				<ec:switchColumn property="TOPIC_IS_DEL" title="删除" width="8%" defaultValues="false,true">
					未删除||已删除			
				</ec:switchColumn>										
				<ec:column property="TOPIC_ADD_TIME" title="发表时间"  cell="date"/>	
				<ec:column property="TOPIC_LAST_RE_TIME" title="最后更新"  cell="date"/>					
		</ec:row>
	</ec:table>
<table border="0" width="100%">
	<tr valign="top">
		<td align="right">
		<input name="selectAll" type="checkbox" id="selectAll" onclick="selectAllBox(document.theform.topicId);"/>全（反）选
		&nbsp;&nbsp;&nbsp; 
		<select name="actionFlag" id="actionFlag">
			<option value="0" selected="selected">请选择</option>
			<option value="1">审核主题</option>
			<option value="2">删除主题至回收站</option>
			<option value="3">恢复主题</option>			
		</select>&nbsp;&nbsp;&nbsp;
		<button class="btn" accessKey=c id="btnConfirm" name="btnConfirm" title="确定" onclick="javascript:doConfirm(document.theform.topicId);">确定(<u>C</u>)</button>
		&nbsp;&nbsp;&nbsp; 
		<button class="btn" accessKey=r id="btnRefresh" name="btnRefresh" title="刷新当前页面" onclick="javascript:location.reload();this.disabled=true;">刷新(<u>R</u>)</button>
		&nbsp;&nbsp;&nbsp;<td>
	</tr>
</table>
<%=COPYRIGHTFOOT%>		
<%@ include file="../common/foot.inc"%>	
</body>
</html>
